package com.test.nnooolwdeaer.view_wooden.widget_wooden;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.text.InputType;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.test.nnooolwdeaer.R;
import com.test.nnooolwdeaer.util_wooden.StringUtil_wooden;
import com.test.nnooolwdeaer.view_wooden.TrackEditText;

public class InputView_wooden extends LinearLayout {

    private String title_wooden;
    private String hint_wooden;
    private int inputType_wooden;

    private TextView titleTv_wooden;
    private TrackEditText inputEt_wooden;

    public InputView_wooden(Context context) {
        super(context);
        init_wooden(context,null);
    }

    public InputView_wooden(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init_wooden(context,attrs);
    }

    public InputView_wooden(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init_wooden(context,attrs);
    }

    private void init_wooden(Context context, AttributeSet attrs){

        String trackName = "";

        if (attrs!=null){
            @SuppressLint({"Recycle", "CustomViewStyleable"}) TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.InputView);
            title_wooden = typedArray.getString(R.styleable.InputView_title);
            hint_wooden = typedArray.getString(R.styleable.InputView_android_hint);
            inputType_wooden = typedArray.getInt(R.styleable.InputView_android_inputType, InputType.TYPE_CLASS_TEXT);
            trackName = typedArray.getString(R.styleable.InputView_trackName);
        }

        View view = View.inflate(context, R.layout.view_input_wooden,this);
        titleTv_wooden = view.findViewById(R.id.view_input_tv_title);
        inputEt_wooden = view.findViewById(R.id.view_input_et_input);

        inputEt_wooden.sTrackWord(trackName);

        if (TextUtils.isEmpty(title_wooden)) titleTv_wooden.setVisibility(GONE);
        else titleTv_wooden.setText(title_wooden);

        inputEt_wooden.setHint(StringUtil_wooden.getSafeString_wooden(hint_wooden));

        inputEt_wooden.setInputType(inputType_wooden);
    }

    public boolean isInputEmpty(){
        return TextUtils.isEmpty(inputEt_wooden.getText());
    }

    public String getInput_wooden(){
        return StringUtil_wooden.getSafeString_wooden(inputEt_wooden.gText());
    }

    public void setInput_wooden(String text){
        inputEt_wooden.setText(StringUtil_wooden.getSafeString_wooden(text));
    }

}
